package com.sqq.testdemo.activity;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.sqq.testdemo.R;

public class UIWidgetActivity extends AppCompatActivity {

    private EditText text;
    private Button btn_alertDialog,btn_progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uiwidget);

        btn_alertDialog = (Button) findViewById(R.id.btn_alertDialog);
        btn_progressDialog = (Button) findViewById(R.id.btn_progressDialog);
        btn_alertDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showAlertDialog();
            }
        });
        btn_progressDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgressDialog();
            }
        });

        Button btn_widget = (Button) findViewById(R.id.btn_widget);
        text = (EditText) findViewById(R.id.text);
        final ImageView iv_click = (ImageView) findViewById(R.id.iv_click);
        iv_click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_click.setImageResource(R.mipmap.bg);
            }
        });
        btn_widget.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String input = text.getText().toString();
                Toast.makeText(UIWidgetActivity.this,"您输入的内容为："+input,Toast.LENGTH_SHORT).show();
            }
        });

    }


    /**
     * 弹出ProgressDialog对话框
     */
    private void showProgressDialog() {
        ProgressDialog dialog = new ProgressDialog(this);
        dialog.setTitle("进度提示");
        dialog.setMessage("正在玩命加载中...");
        dialog.show();
    }
    /**
     * 弹出AlertDialog对话框
     */
    private void showAlertDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.mipmap.what);
        builder.setTitle("警告");
        builder.setMessage("前方凶险万分，你是否还要继续前往？");
        builder.setCancelable(false);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(UIWidgetActivity.this,"您已经确定以身犯险",Toast.LENGTH_SHORT).show();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(UIWidgetActivity.this,"您放弃了挑战自己的机会",Toast.LENGTH_SHORT).show();
            }
        });
        builder.show();
    }
}
